package com.lab.rx;

import android.view.View;

import com.jakewharton.rxbinding.widget.TextViewTextChangeEvent;

/**
 * RxJava 监听目标EditText为空时，另外一个view是否enable
 * Created by ak
 */
public class TextChangeTargetEnabledSubscriber extends BaseSubscriber<TextViewTextChangeEvent> {
    private View target;
    /**
     * 正相关与反相关
     */
    public boolean isPositive = true;

    public TextChangeTargetEnabledSubscriber setTarget(View target) {
        return setTarget(target, true);
    }


    public TextChangeTargetEnabledSubscriber setTarget(View target, boolean isPositive) {
        this.target = target;
        this.isPositive = isPositive;
        return this;
    }

    @Override
    public void onNext(TextViewTextChangeEvent event) {
        boolean enable = event.text().length() > 0;
        if (isPositive){
            target.setEnabled(enable);
        }else{
            target.setEnabled(!enable);
        }
    }

}
